//顺序队列
#ifndef __SEQUENTIALQUEUE__HPP
#define __SEQUENTIALQUEUE__HPP

#include"VirtualQueue.hpp"

namespace NgSiuKei {

template<class TheClass>
class SequentialQueue: public VirtualQueue<TheClass> {
    public:
    SequentialQueue(void);
    ~SequentialQueue(void);

    public:
    //清空
    void clear(void);
    //获取队头元素
    TheClass getFrontVal(void) const;
    //入队列
    void push(const TheClass val);
    //出队列
    TheClass pop(void);
    //打印队列
    void print(void) const;

    private:
    TheClass *p;
};

template<class TheClass>
SequentialQueue<TheClass>::SequentialQueue(void): VirtualQueue<TheClass>() {
    this->p = new TheClass[MAX_SIZE];
}

template<class TheClass>
SequentialQueue<TheClass>::~SequentialQueue(void) {
    delete this->p;
}

template<class TheClass>
void SequentialQueue<TheClass>::clear(void) {
    this->size = 0;
}

template<class TheClass>
TheClass SequentialQueue<TheClass>::getFrontVal(void) const {
    if(this->isEmpty()) {
        throw EXCEPTION_IS_EMPTY;
    }
    return this->p[0];
}

template<class TheClass>
void SequentialQueue<TheClass>::push(const TheClass val) {
    if(MAX_SIZE == this->size) {
        throw EXCEPTION_IS_FULL;
    }
    this->p[this->size] = val;
    this->size++;
}

template<class TheClass>
TheClass SequentialQueue<TheClass>::pop(void) {
    if(this->isEmpty()) {
        throw EXCEPTION_IS_EMPTY;
    }
    
    TheClass resultVal = this->p[0];
    this->size--;
    for(U_L_L i=0; i<this->size; ++i) {
        this->p[i] = this->p[i+1];
    }
    return resultVal;
}

template<class TheClass>
void SequentialQueue<TheClass>::print(void) const {
    cout << "打印顺序队列：[ ";
    for(int i=0; i<this->size; ++i) {
        cout << this->p[i] << ' ';
    }
    cout << ']' << endl;
}

}

#endif